import { getOrderInfoPageList } from '../../api/index';

export const _toggleListLoading = (payload) => {
  return {
    type: 'TOGGLE_LIST_LOADING',
    payload,
  };
};

export const _getOrderListDataInfoData = (payload) => {
  return {
    type: 'GET_ORDER_LISTDATA_INFO',
    payload,
  };
};

export function getOrderListDataInfo({ page, limit, searchObj }) {
  return async (dispatch) => {
    try {
      await dispatch(_toggleListLoading(true));
      const listResult = await getOrderInfoPageList(page, limit, searchObj);
      const listDataObj = {
        list: listResult.records,
        pages: listResult.pages,
        total: listResult.total,
      };

      await dispatch(_getOrderListDataInfoData(listDataObj));
      await dispatch(_toggleListLoading(false));
    } catch (error) {
      await dispatch(_toggleLoading(false));
      await dispatch(_toggleListLoading(false));
      console.log(error);
    }
  };
}
